package com.lhj.es.service;

import com.lhj.es.common.HelloRetryException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author linghaijin
 * @date 2021-04-22 10:47
 */
@Slf4j
@Service
public class HelloRetryService implements IHelloService{

    @Autowired
    private HelloService helloService;

    @Override
    public String hello() {
        int maxRetryTime = 4;
        String s = "";
        for (int i = 0; i < maxRetryTime; i++) {
            try {
                s = helloService.hello();
                log.info("helloService返回:{}", s);
                return s;
            } catch (HelloRetryException e) {
                log.info("helloService.hello() 调用失败，准备重试");
            }
        }

        throw new HelloRetryException("重试次数耗尽");
    }



}
